import { defineStore } from "pinia";
import router from "@/router"; // 假设使用 Vue Router

import { ElMessageBox } from "element-plus";
import {
  getSystemProperties,
  getSystemPropertiesBatch,
} from "@/api/system/properties/properties.js";
import { ref } from "vue";
import { PropertiesDto, PropertiesBatchDto } from "@/model/properties.d.js";

export const useSystemStore = defineStore("systemStore ", {
  state: () => ({
    // 书本审核状态
    contributeJudgeDictionary: ref({
      20101: "待审核",
      20102: "审核通过",
      20103: "审核失败",
    }),
    // 评论审核状态
    commentJudgeDictionary: ref({}),
    // 固有成员，系统列表
    systemInitList: ["comment-judge-state", "contribute-judge-state"],
  }),

  actions: {
    /**
     * 初始化函数
     * @returns
     */
    async systemDictionaryInit() {
      // 初始化判断
      if (!this.isInit) {
        this.isInit = true;
      } else {
        return;
      }
      /*
      在此处添加你的初始化代码（配置信息）
      配置原理：src/router/index.js中有路由守卫
      router.beforeEach(async (to, from, next) => {
        // 访问连接后立即执行的代码
        const systemStore = useSystemStore();
        // MARK 系统初始化完成之后才进行后续的响应
        await systemStore.systemDictionaryInit();
        next();
      });
       */
    },

    /**
     * 获取一个系统属性
     * @param {*} params
     */
    async testGetOne(params) {
      var query = new PropertiesDto();
      query.key = "comment-judge-state";
      const systemProperties = await getSystemProperties(query);
      console.log("systemProperties", systemProperties);
    },
    /**
     * 登录成功事件
     */
    async userLoginSuccess() {
      await ElMessageBox({ message: "登录成功", type: "success" });
      router.push({ path: "/index" });
    },
  },
});
